package com.company.project.web.system.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.company.project.common.enums.RestCodeEnum;
import com.company.project.common.pojo.Rest;
import com.company.project.common.utils.RestUtil;
import com.company.project.web.system.pojo.technician_serviceitem.TechnicianServiceitem;
import com.company.project.web.system.pojo.user.User;
import com.company.project.web.system.service.TechnicianServiceitemService;
import com.company.project.web.system.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2019-09-10
 */
@Controller
@RequestMapping("/system/technician-serviceitem")
public class TechnicianServiceitemController {

    @Autowired
    private TechnicianServiceitemService technicianServiceitemService;

    @ApiOperation(value = "修改技师的服务项目")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "xxxToken", value = "请求头token", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "userId", value = "用户id",  required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType="query", name = "serviceitemIds", value = "服务项目ids",  required = true, dataType = "Integer")
    })
    @RequestMapping(value = "updateTechnicianServiceitem", method = RequestMethod.POST)
    @ResponseBody
    public Rest updateTechnicianServiceitem(Integer userId, Integer[] serviceitemIds){
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.eq("technician_id", userId);

        for (Integer serviceitemId: serviceitemIds){
            TechnicianServiceitem technicianServiceitem = new TechnicianServiceitem();
            technicianServiceitem.setServiceitemId(serviceitemId);
            technicianServiceitemService.update(technicianServiceitem, wrapper);
        }

        return RestUtil.rest(RestCodeEnum.CODE_200.getCode(), RestCodeEnum.CODE_200.getDesc());
    }

}

